/**
 * 用户组分页
 */
$(function () {
	_tableshow();
});
function _tableshow() {
	var currentPage = 1;//起始页
	var size = 2;//每页显示条数
    $.ajax({
    	url: "../channel/getGroupList.do",
    	datatype: 'json',
    	type: "Post",
    	data: {
    		page:currentPage,
    		size:size
    	},
    	success: function (data) {
    		if (data != null) {
    			var html;
       			$.each(eval("(" + data + ")").list, function (index, item) { //遍历返回的json
       				html = html + "<tr>";
       				html = html + "<td class='center'>"+item.mid+"</td>";
       				html = html + "<td class='center'>"+item.name+"</td>";
       				html = html + "<td class='hidden-480 center'><img id='logo' style='width:45px;height:45px;' src='"+item.logo+"'/>"+"</td>";
       				if(item.sex==0){
       					html = html + "<td class='center'>"+"男</td>";
       				}else if(item.sex==1){
       					html = html + "<td class='center'>"+"女</td>";
       				}
       				html = html + "<td class='center'>"+item.phone+"</td>";
       				html = html + "<td class='center'>"+item.email+"</td>";
       				html = html + "<td class='center'>"+item.city+"</td>";
       				html = html + "</div></td>";
       				html = html + "</tr>";
       			});
       			$("#list").html(html);
    		var pageCount = eval("(" + data + ")").pageCount; // 取到pageCount的值(把返回数据转成object类型)
    		var currentPage = eval("(" + data + ")").CurrentPage; // 得到CurrentPage
    		var options = {
    				currentPage: currentPage, // 当前页数
    				totalPages: pageCount, // 总页数
    				itemTexts: function (type, page, current) {
    					switch (type) {
    					case "first":
    						return "首页";
    					case "prev":
    						return "上一页";
    					case "next":
    						return "下一页";
    					case "last":
    						return "末页";
    					case "page":
    						return page;
    					}
    				},// 点击事件，用于通过Ajax来刷新整个list列表
    				onPageClicked: function (event, originalEvent, type, page) {
    					$.ajax({
    						url: "../channel/getGroupList.do?",
    						type: "Post",
    						data: {
    				    		page:page,
    				    		size:size
    				    	},
    						success: function (data1) {
    							if (data1 != null) {
    								var html;
    								$.each(eval("(" + data1 + ")").list, function (index, item) { // 遍历返回的json
    									html = html + "<tr>";
    				       				html = html + "<td class='center'>"+item.mid+"</td>";
    				       				html = html + "<td class='center'>"+item.name+"</td>";
    				       				html = html + "<td class='hidden-480 center'><img id='logo' style='width:45px;height:45px;' src='"+item.logo+"'/>"+"</td>";
    				       				if(item.sex==0){
    				       					html = html + "<td class='center'>"+"男</td>";
    				       				}else if(item.sex==1){
    				       					html = html + "<td class='center'>"+"女</td>";
    				       				}
    				       				html = html + "<td class='center'>"+item.phone+"</td>";
    				       				html = html + "<td class='center'>"+item.email+"</td>";
    				       				html = html + "<td class='center'>"+item.city+"</td>";
    				       				html = html + "</div></td>";
    				       				html = html + "</tr>";								
    				       			});
    								$("#list").html(html);
    							}
    						}
    					});
    				}
    			};
          $('#group_table').bootstrapPaginator(options);
        }
      }
    });
}